package main;

import dao.DataManager;
import model.User;
import model.UserType;
import util.InputUtil;
import view.AdminView;
import view.FrontDeskView;
import view.LoginView;
import view.ManagerView;

public class Main {
    private static final DataManager dataManager = DataManager.getInstance();
    private static User currentUser = null;

    public static void main(String[] args) {
        showMainMenu();
    }

    private static void showMainMenu() {
        while (true) {
            System.out.println("\n===== 万东电影院管理系统 =====");
            System.out.println("1. 登录系统");
            System.out.println("2. 退出系统");
            System.out.print("请选择操作: ");

            int choice = InputUtil.readIntRange("", 1, 2);

            switch (choice) {
                case 1:
                    login();
                    break;
                case 2:
                    exitSystem();
                    return;
            }
        }
    }

    private static void login() {
        LoginView loginView = new LoginView();
        currentUser = loginView.login();

        if (currentUser != null) {
            switch (currentUser.getUserType()) {
                case ADMIN:
                    AdminView adminView = new AdminView(currentUser);
                    adminView.showMenu();
                    break;
                case MANAGER:
                    ManagerView managerView = new ManagerView(currentUser);
                    managerView.showMenu();
                    break;
                case FRONT_DESK:
                    FrontDeskView frontDeskView = new FrontDeskView(currentUser);
                    frontDeskView.showMenu();
                    break;
            }
            currentUser = null;
        }
    }

    private static void exitSystem() {
        System.out.println("感谢使用万东电影院管理系统，再见！");
        dataManager.saveData();
    }
} 